package com.zhangyx.crawler.proxy;

import java.io.Serializable;

public class ProxyEntity implements Serializable{
    private String host;
    private int port;
    private String type; // http https

    public String getHost() {
        return host;
    }

    public void setHost(String host) {
        this.host = host;
    }

    public int getPort() {
        return port;
    }

    public void setPort(int port) {
        this.port = port;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public static ProxyEntity convert(String host, String portStr, String type) {
        int port = 0;
        if (host == null || host.equals("")) {
            return null;
        }
        if (portStr == null || portStr.equals("")) {
            return null;
        }
        if (type == null || type.equals("")) {
            return null;
        }
        try {
            port = Integer.parseInt(portStr);
        } catch (Exception e) {
            return null;
        }
        ProxyEntity entity = new ProxyEntity();
        entity.setHost(host);
        entity.setPort(port);
        entity.setType(type);
        return entity;
    }

    @Override
    public String toString() {
        return host + ":" + port + "#" + type;
    }
}
